//
//  PopoverPresentationController.swift
//  SinaWeibo
//
//  Created by paycloud110 on 16/6/2.
//  Copyright © 2016年 paycloud110. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    var presentedFrame: CGRect = CGRectZero
    
    /** 布局被弹出来的控制器 */
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        /** containView是所有显示的容器 */
        containerView?.insertSubview(coverView, atIndex: 0)
        coverView.frame = containerView!.bounds
        
        presentedView()?.frame = presentedFrame
    }
    @objc private func coverClick() {
    
        // dismiss控制器
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
    // MARK: - layz
    private lazy var coverView: UIView = {
        let otherView = UIView()
        otherView.backgroundColor = UIColor(white: 0.9, alpha: 0.3)
        let gesture = UITapGestureRecognizer(target: self, action: Selector("coverClick"))
        otherView.addGestureRecognizer(gesture)
        return otherView
    }()

}
